using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using UnityEngine;

public class HOLocalizationConfiguration : HOConfigurationReader
{
	private static HOLocalizationConfiguration m_Instance;

	public TextAsset m_TextAsset;

	protected Dictionary<int, Hashtable> m_DicTable = new Dictionary<int, Hashtable>();

	public static HOLocalizationConfiguration Instance => m_Instance;

	public static string GetValue(int id)
	{
		if (Instance == null)
		{
			return string.Empty;
		}
		return Instance.m_DicTable[id][ConstantData.GameLanguage.ToString()].ToString();
	}

	public virtual void ParseTextAsset()
	{
		XmlDocument xmlDocument = new XmlDocument();
		XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmlDocument.NameTable);
		xmlNamespaceManager.AddNamespace("o", "urn:schemas-microsoft-com:office:office");
		xmlNamespaceManager.AddNamespace("x", "urn:schemas-microsoft-com:office:excel");
		xmlNamespaceManager.AddNamespace("ss", "urn:schemas-microsoft-com:office:spreadsheet");
		//xmlNamespaceManager.AddNamespace("html", "http://www.w3.org/TR/REC-html40");
		xmlDocument.LoadXml(m_TextAsset.text);
		XmlNodeList xmlNodeList = xmlDocument.DocumentElement.SelectNodes("//ss:Worksheet/ss:Table/ss:Row", xmlNamespaceManager);
		XmlNodeList xmlNodeList2 = xmlNodeList[0].SelectNodes("ss:Cell", xmlNamespaceManager);
		string[] array = new string[xmlNodeList2.Count];
		int i = 0;
		for (int num = array.Length; i < num; i++)
		{
			array[i] = xmlNodeList2[i].SelectSingleNode("ss:Data", xmlNamespaceManager).InnerText.Trim();
		}
		for (int j = 2; j < xmlNodeList.Count; j++)
		{
			XmlNodeList xmlNodeList3 = xmlNodeList[j].SelectNodes("ss:Cell", xmlNamespaceManager);
			Hashtable hashtable = new Hashtable();
			int num2 = 0;
			for (int k = 0; k < array.Length; k++)
			{
				XmlNode xmlNode = xmlNodeList3[num2];
				if (xmlNode == null)
				{
					continue;
				}
				if (xmlNode.Attributes["ss:Index"] != null)
				{
					int num3 = k;
					k = int.Parse(xmlNode.Attributes["ss:Index"].Value) - 1;
					if (k >= array.Length)
					{
						for (int l = num3; l < array.Length; l++)
						{
							hashtable[array[l]] = "0";
						}
						break;
					}
					for (int m = num3; m < k; m++)
					{
						hashtable[array[m]] = "0";
					}
				}
				XmlNode xmlNode2 = xmlNode.SelectSingleNode("ss:Data", xmlNamespaceManager);
				string key = array[k];
				string empty = string.Empty;
				empty = (string)(hashtable[key] = ((xmlNode2 == null || !(xmlNode2.InnerText != string.Empty)) ? "0" : xmlNode2.InnerText));
				num2++;
			}
			int key2 = int.Parse(hashtable["ID"].ToString());
			m_DicTable.Add(key2, hashtable);
		}
	}

	private void PrintValue()
	{
		foreach (KeyValuePair<int, Hashtable> item in m_DicTable)
		{
			string text = item.Key.ToString();
			IDictionaryEnumerator enumerator2 = m_DicTable[item.Key].GetEnumerator();
			try
			{
				while (enumerator2.MoveNext())
				{
					DictionaryEntry dictionaryEntry = (DictionaryEntry)enumerator2.Current;
					string text2 = text;
					text = text2 + " :" + dictionaryEntry.Key + "-" + dictionaryEntry.Value + ": ";
				}
			}
			finally
			{
				IDisposable disposable;
				if ((disposable = (enumerator2 as IDisposable)) != null)
				{
					disposable.Dispose();
				}
			}
		}
	}

	private void Awake()
	{
		if (m_Instance == null)
		{
			m_Instance = this;
			UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
			ParseTextAsset();
		}
		else
		{
			UnityEngine.Object.Destroy(this);
		}
	}

	public void OnApplicationQuit()
	{
		m_Instance = null;
	}
}
